<template>
  <div>
    <cus-modal
      ref="modal"
      title="消耗汇总清单报表导出"
      width="450"
      @on-visible-change="onVisibleChange"
      @onOk="onOk"
    >
      <Form ref="formValidate" :model="form" :rules="ruleValidate" style="margin-bottom:-20px;">
        <FormItem
          label="消耗汇总导出日期："
          :label-width="178"
          prop="resourceType"
        >
          <DatePicker
            class="itemImport"
            type="daterange"
            :value="time"
            placeholder="开始日期 - 结束日期"
            @on-change="daterangeChange"
            style="width: 200px; margin-bottom:-15px;"
          />
        </FormItem>
      </Form>
      <Spin size="large" fix v-if="loading"></Spin>
    </cus-modal>
  </div>
</template>

<script>
// import { postApiGoodsSelectConsumeCollect } from "@/api/business/manager";
const form = {
  id: "",
  startDate: "", //开始时间
  stopDate: "", //结束时间
};

export default {
  components: {},
  name: "",
  data() {
    return {
      loading: false,
      ruleValidate: {},
      form: form,
      time:[],
    };
  },
  computed: {},
  mounted() {
    this.form = this.$cu.deepClone(form);
  },
  methods: {
    onVisibleChange(v) {
      this.$refs["formValidate"].resetFields();
      if (!v) this.form = this.$cu.deepClone(form);
    },
    show() {
      this.loading = false;
      this.$refs["modal"].show = true;
    },
    //消耗记录-消耗汇总导出日期事件
    daterangeChange(v) {
      this.form.startDate = v[0];
      this.form.stopDate = v[1];
      this.time.push(v[0]);
      this.time.push(v[1])
    },
    onOk() {
      this.postApiGoodsSelectConsumeCollectApi();
    },
    //消耗记录消耗汇总导出-----------------接口
    postApiGoodsSelectConsumeCollectApi() {
    this.form.loading = true;
      return new Promise((resolve) => {
        let params = {
          startDate: this.form.startDate, //开始时间
          stopDate: this.form.stopDate, //结束时间
        };
        postApiGoodsSelectConsumeCollect(params).then((res) => {
          this.form.loading = false;
          this.time=[];
          if (res.retCode == 2000) {
            window.location.href = res.data;
            this.$refs["modal"].show = false;
             resolve();
          } else {
            this.form.loading = false;
            this.$Message.error(res.retMsg);
          }
        })
      });
    },
  },
};
</script>

<style scoped>
</style>
